home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ML_3DROT.ZIP / SOURCES / FIG10.PAS < prev    next >
Pascal/Delphi Source File  |  1996-12-26  |  4KB  |  194 lines

  1. {
  2.   Example of using the 3D "engine", by Maple Leaf, 1996
  3.  
  4.   This code is freeware. If you find it useful, feel free to do whatever
  5.   you want with it, with only one condiion: give some small greetings to
  6.   Maple Leaf in your productions that use parts of it.
  7.  
  8.                                                         Maple Leaf, '96
  9.  
  10.   btw, I'm too lazy to write down kilos of comments...   :-)
  11. }
  12.  
  13. uses xmode,crt,engine3d;
  14.  
  15. var a,b:word;
  16.     pal:array[byte] of record r,g,b:byte end;
  17.     capag,cvpag : word;
  18.     dd:integer;
  19.     coord:array[0..720] of record x,y,z:integer end;
  20.     RealMapping : Boolean;
  21.     ch:char;
  22.     MaxPnt:word;
  23.     RotStep,TiltStep:longint;
  24.  
  25. Procedure GenFig;
  26. var cnt,k:word;
  27. begin
  28.   cnt:=0;
  29.   for k:=0 to 59 do begin
  30.     with coord[cnt] do begin
  31.       x:=k; y:=0; z:=0;
  32.     end;
  33.     inc(cnt);
  34.   end;
  35.   for k:=0 to 59 do begin
  36.     with coord[cnt] do begin
  37.       x:=60; y:=0; z:=k;
  38.     end;
  39.     inc(cnt);
  40.   end;
  41.   for k:=0 to 59 do begin
  42.     with coord[cnt] do begin
  43.       x:=60-k; y:=0; z:=60;
  44.     end;
  45.     inc(cnt);
  46.   end;
  47.   for k:=0 to 59 do begin
  48.     with coord[cnt] do begin
  49.       x:=0; y:=0; z:=60-k;
  50.     end;
  51.     inc(cnt);
  52.   end;
  53.   for k:=0 to 59 do begin
  54.     with coord[cnt] do begin
  55.       x:=0; y:=k; z:=0;
  56.     end;
  57.     inc(cnt);
  58.   end;
  59.   for k:=0 to 59 do begin
  60.     with coord[cnt] do begin
  61.       x:=k; y:=60; z:=0;
  62.     end;
  63.     inc(cnt);
  64.   end;
  65.   for k:=0 to 59 do begin
  66.     with coord[cnt] do begin
  67.       x:=60; y:=60; z:=k;
  68.     end;
  69.     inc(cnt);
  70.   end;
  71.   for k:=0 to 59 do begin
  72.     with coord[cnt] do begin
  73.       x:=60-k; y:=60; z:=60;
  74.     end;
  75.     inc(cnt);
  76.   end;
  77.   for k:=0 to 59 do begin
  78.     with coord[cnt] do begin
  79.       x:=0; y:=60; z:=60-k;
  80.     end;
  81.     inc(cnt);
  82.   end;
  83.   for k:=0 to 59 do begin
  84.     with coord[cnt] do begin
  85.       x:=60; y:=60-k; z:=0;
  86.     end;
  87.     inc(cnt);
  88.   end;
  89.   for k:=0 to 59 do begin
  90.     with coord[cnt] do begin
  91.       x:=60; y:=60-k; z:=60;
  92.     end;
  93.     inc(cnt);
  94.   end;
  95.   for k:=0 to 59 do begin
  96.     with coord[cnt] do begin
  97.       x:=0; y:=60-k; z:=60;
  98.     end;
  99.     inc(cnt);
  100.   end;
  101.   MaxPnt:=cnt;
  102. end;
  103. Procedure PuneFig;
  104. var i:integer; cnt:word;
  105. begin
  106.   cnt:=0;
  107.   {xvwait;}
  108.   xclrvpage(capag);
  109.   for i:=0 to MaxPnt-1 do begin
  110.     _3dx:=coord[i].x+100;
  111.     _3dy:=coord[i].y+10;
  112.     _3dz:=coord[i].z+10;
  113.     asm
  114.        cmp RealMapping,1
  115.        je @1
  116.        call IntMapCoordinates
  117.        jmp @2
  118.     @1:call MapCoordinates
  119.     @2:
  120.     end;
  121.     xvplot(_2dx,_2dy,(i+1) shl 3,capag);
  122.   end;
  123. end;
  124.  
  125. Procedure IntroText;
  126. begin
  127.   Writeln('3D Figure, by Maple Leaf, 1996.');
  128.   Writeln(#13#10,' Hot keys are:'#13#10);
  129.   Writeln('   <M>     - Change mapping method (float/integer)');
  130.   Writeln('   <Left>  - Decrement horizontal speed of rotation');
  131.   Writeln('   <Right> - Increment horizontal speed of rotation');
  132.   Writeln('   <Up>    - Increment vertical speed of rotation');
  133.   Writeln('   <Down>  - Decrement vertical speed of rotation');
  134.   Writeln(#13#10'Press a key to start ...');
  135.   Readkey;
  136. end;
  137.  
  138. begin
  139.   ClrScr;
  140.   GenFig;
  141.   IntroText;
  142.   xinitvideo(0);
  143.   xclrvram;
  144.   for a:=1 to 255 do with pal[a] do begin
  145.     r:=Trunc(63-63*a/255);
  146.     g:=Trunc(63-63*a/255);
  147.     b:=Trunc(63*a/255);
  148.   end;
  149.   xsetpalette(@pal);
  150.   ZoomFactor:=500;
  151.   SetObserverPosition(0,0,500);
  152.   SetAngles(0,0);
  153.   capag:=0;
  154.   cvpag:=3;
  155.   dd:=10;
  156.   RealMapping:=false;
  157.   RotStep:=2;
  158.   TiltStep:=3;
  159.   repeat
  160.    repeat
  161.  
  162.     xvwait;
  163.     xsetvpage(cvpag);
  164.  
  165.     RotAngle:=RotAngle+RotStep;
  166.     TiltAngle:=TiltAngle+TiltStep;
  167.     if RotAngle>359 then RotAngle:=360-RotAngle;
  168.     if RotAngle<0 then RotAngle:=360+RotAngle;
  169.     if TiltAngle>359 then TiltAngle:=360-TiltAngle;
  170.     if TiltAngle<0 then TiltAngle:=360+TiltAngle;
  171.     {SetAngles(RotAngle,TiltAngle);}
  172.  
  173.     PuneFig;
  174.  
  175.     inc(capag); if capag>3 then capag:=0;
  176.     inc(cvpag); if cvpag>3 then cvpag:=0;
  177.  
  178.    until keypressed;
  179.    ch:=readkey;
  180.    case UpCase(ch) of
  181.      'M': { Mapping mode } RealMapping:=not RealMapping;
  182.      #0: begin
  183.        ch:=readkey;
  184.        case ch of
  185.          #72: {Up}    inc(RotStep);
  186.          #80: {Down}  dec(RotStep);
  187.          #75: {Left}  dec(TiltStep);
  188.          #77: {Right} inc(TiltStep);
  189.        end;
  190.      end;
  191.    end;
  192.   until ch=#27;
  193.   textmode(25);
  194. end.